package com.zzptc.easyshop.control;

import com.zzptc.easyshop.dao.UserDao;
import com.zzptc.easyshop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "RegServlet")
public class RegServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         PrintWriter pw= response.getWriter();
       //  pw.print("hello");
        //接收用户请求
      String username=  request.getParameter("userName");
      String pwd=  request.getParameter("passWord");
      pw.print(username+",hello");

      //调用组件新增数据
        UserDao userDao=new UserDao();//?单例没有实现
        Users user=new Users();
        user.setEu_user_id("6");
        user.setEu_user_name(username);
        user.setEu_password(pwd);
        boolean b=false;
        try {
            b=userDao.insert(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(b){
            System.out.println("succ");
        }else{
            System.out.println("error");
        }

    }
}
